package lt.hsu.web;

import lombok.Data;

@Data
public class ApiResponse<T> {

    private final long responseTime;

    private final long code;

    private final T data;

    private String message;

    public ApiResponse(long code, String message, T data){
        this.code = code;
        this.data = data;
        this.message = message;
        this.responseTime = System.currentTimeMillis();
    }

    public ApiResponse(long code, String message){
        this.code = code;
        this.message = message;
        this.responseTime = System.currentTimeMillis();
        this.data = null;
    }

    public ApiResponse(ErrorCode errorCode){
        this(errorCode.getCode(), errorCode.getMessage());
    }

    public ApiResponse(ErrorCode errorCode, T data){
        this(errorCode.getCode(), errorCode.getMessage(),data);
    }

    public static <T> ApiResponse<T> success(T data){
        return new ApiResponse<>(EApiReturn.SUCCESS,data);
    }

    public static <T> ApiResponse<T> failure(){
        return new ApiResponse<>(EApiReturn.FAILURE);
    }

}
